//
//  TravelNoteCommentViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/17.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "TravelNoteCommentViewController.h"
#import "UIPlaceHolderTextView.h"

@interface TravelNoteCommentViewController ()<UITextFieldDelegate, UITableViewDelegate>;
@property (nonatomic, strong)UIPlaceHolderTextView * textView;

@end

@implementation TravelNoteCommentViewController(Networking)
- (void)submitComment{
    NSDictionary * dic = @{
                           @"did":@(self.did),
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token,
                           @"type":@(1),
                           @"content":self.textView.text
                           };
    WS(ws)
    [[HUDHelper sharedInstance]syncLoading:@"翻箱中..."];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/diary/toComment") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [[HUDHelper sharedInstance]syncStopLoading];
        if (error)
        {
            [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
        }
        else
        {
            if ([obj[@"code"] integerValue] == 100000)
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
                [ws.navigationController popViewControllerAnimated:YES];
            }
            else
            {
                [[HUDHelper sharedInstance]tipMessage:obj[@"msg"]];
            }
        }
    }];
}

@end

@implementation TravelNoteCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UITableView * tableView = [[UITableView alloc] init];
    tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.view.backgroundColor = [UIColor whiteColor];
    _textView = [[UIPlaceHolderTextView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 150)];
    _textView.backgroundColor = getColor(bgColor);
    self.textView.placeholder = @"请输入您要评论的内容";
    
    UIButton * submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [submitButton setTitle:@"提交" forState:UIControlStateNormal];
    submitButton.backgroundColor = getColor(@"ffbb02");
    submitButton.layer.cornerRadius = 8;
    submitButton.titleLabel.font = DEF_FontSize_14;
    submitButton.layer.masksToBounds = YES;
    [submitButton addTarget:self action:@selector(submitButtonAction) forControlEvents:UIControlEventTouchUpInside];
    submitButton.frame = CGRectMake(15, tableView.bottom - 64 - 60, SCREEN_WIDTH - 30, 40);
    [tableView addSubview:submitButton];
    [tableView addSubview:self.textView];
    [self.view addSubview:tableView];
    
//    UIButton * submitBtn = [[UIButton alloc] init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.textView resignFirstResponder];
}

- (void)submitButtonAction{
    NSLog(@"提交评论");
    [self submitComment];
}

@end
